#define DBG_MEM
#define LLOG(fmt, ...) printf("%s %s() %d "fmt, __FILE__, __func__, __LINE__, ##__VA_ARGS__)
#define LOGERR(fmt, ...) printf("%s %s() %d "fmt, __FILE__, __func__, __LINE__, ##__VA_ARGS__)
#define LOGFEW(fmt, ...) do { \
    static time_t last_ts = 0; time_t curr_ts = time(NULL); if (((unsigned)(curr_ts - last_ts)) >= 10) { last_ts = curr_ts; printf("%s %s() %d "fmt, __FILE__, __func__, __LINE__, ##__VA_ARGS__); } } while(0)
#include "memleak.h"
#include <stdlib.h>
#include <stdio.h>

struct memleak_handle memleak_handle;
struct log_handle *log_handle = NULL;
int log_with_ts = 0;
int log_with_func = 0;
int log_with_file = 0;
int log_with_line = 0;
int verbose = 1;
int log_file_info_width = 10;
int log_func_info_width = 10;

int main()
{
    MEMLEAK_INIT;
    char *p = NULL;
    int i;
    for (i = 0; i < 3; i++) {
        p = malloc(1);
        p = malloc(2);
        free(p); p = NULL;
        p = calloc(1, 3);
        p = calloc(1, 4);
        free(p); p = NULL;
        p = realloc(p, 5);
        p = realloc(p, 6);
        free(p); p = NULL;
        strdup("123456789");
        strndup("123456789", 5);
    }
    memleak_stat(NULL, 0, NULL, 0);

    p = malloc(1);
    raw_free(p - MEMLEAK_HEAD_SIZE);

    p = malloc(1);
    LOGERR("write invalid address, should crash now\n");
    memset(p, 0, 2);
    free(p);

    return 0;
}
